package grid;

import java.util.Arrays;

public final class GridBuilder {
	private GridPoint[] gridPoints;
	private Grid father;
	public GridBuilder(int size){
		this.gridPoints = new GridPoint[size];
		this.father =null;
	}
	
	/**
	 * 
	 * is called by Grid.getBuilder
	 */
	protected GridBuilder(GridPoint[] gridPoints, Grid father){
		this.gridPoints = Arrays.copyOf(gridPoints,gridPoints.length);
		this.father = father;
	}
	
	public void set(int i, GridPoint p){
		if (father != null) {
			gridPoints[i] =father.get(i).newInstance(p);
		}else{
		gridPoints[i] =p;
		}
	}
	
	public Grid generate(){
		return new Grid(gridPoints, father);
	}

}
